#!/usr/bin/env python
# _*_ coding:utf-8 _*_

import requests
import re
import logging


from ..platform import ManageProcessor,Color

logging.basicConfig(filename='Weblogic.log',
                    format='%(asctime)s %(message)s',
                    filemode="w", level=logging.INFO)

VUL=['CVE-2018-2894']
headers = {'user-agent': 'ceshi/0.0.1'}

@ManageProcessor.plugin_register('CVE20182894')
class CVE20182894(object):
    def process(self,ip,port):
        self.run(ip,port,0)

    def islive(self,ur,port):
        url='http://' + str(ur)+':'+str(port)+'/ws_utc/resources/setting/options/general'
        r = requests.get(url, headers=headers)
        return r.status_code

    def run(self,url,port,index):
        if self.islive(url,port)!=404:
            logging.info('[+]The target weblogic has a JAVA deserialization vulnerability:{}'.format(VUL[index]))
            print(Color.OKBLUE+'[+]The target weblogic has a JAVA deserialization vulnerability:{}'.format(VUL[index])+Color.ENDC)
            print(Color.OKGREEN+'[+]CVE-2018-2894 漏洞存在'+Color.ENDC)
        else:
            logging.info('[-]Target weblogic not detected {}'.format(VUL[index]))
            print(Color.FAIL+'[-]Target weblogic not detected {}'.format(VUL[index])+Color.ENDC)
